import React,{useEffect} from "react";

//路由守卫
import {useLocation,useNavigate} from 'react-router-dom'

function withCpn(Cpn:React.FC){
    function NewCpn(){
        const loca=useLocation()
        const navigate=useNavigate()
        useEffect(()=>{
            let token=localStorage.getItem('token')
            if(!token&&!['/user/login','/user/sigin','/user/forget'].includes(loca.pathname)){
              navigate('/user/login')
            }
            // eslint-disable-next-line react-hooks/exhaustive-deps
        },[loca.pathname])
       return <Cpn></Cpn>
        
    }
    return NewCpn
}
export default withCpn 